#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5+10;

typedef long long ll;

#define pb push_back

struct edge{
	int v,w;
};

vector<edge>G[MAXN];

ll f[MAXN],g[MAXN];
int siz[MAXN],n;

struct node{
	ll tim;int siz;int w;
	bool operator < (const node &b) const{
		return b.siz * tim < siz * b.tim;
	}
};

void dfs(int x,int p){
	siz[x] = 1;
	for(int i = 0;i < (int)G[x].size();i++){
		int y = G[x][i].v;
		if(y == p) continue;
		dfs(y,x);
		f[x] += f[y]; siz[x] += siz[y];
	}
	vector<node> a; a.clear();
	for(int i = 0;i < (int)G[x].size();i++){
		int y = G[x][i].v,w = G[x][i].w;
		if(y == p) continue;
		a.pb((node){g[y]+2*w,siz[y],w});
	}
	sort(a.begin(),a.end());
	for(int i = 0;i < (int)a.size();i++){
		f[x] += (g[x] + a[i].w)* a[i].siz;
		g[x] += a[i].tim;
	}
}

int main (){
	scanf("%d",&n);
	for(int i = 1;i < n;i++){
		int x,y,z;scanf("%d %d %d",&x,&y,&z);
		G[x].pb((edge){y,z});
		G[y].pb((edge){x,z});
	}
	dfs(1,0);
	printf("%lld\n",f[1]);
	return 0;
}
